package com.itheima.tlias.controller;


import com.github.pagehelper.Page;
import com.itheima.tlias.pojo.OperateLog;
import com.itheima.tlias.service.OperateLogService;
import com.itheima.tlias.pojo.PageResult;
import com.itheima.tlias.pojo.Result;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/log")
public class LogController {
    @Resource
    private OperateLogService operateLogService;

    /**
     * 分页查询操作日志
     *
     * @param operateLog 查询条件
     * @param page       页数
     * @param pageSize   每页条数
     * @return 分页结果
     */
    @GetMapping("/page")
    public Result getOperateLog(OperateLog operateLog,
                                @RequestParam(defaultValue = "1") Integer page,
                                @RequestParam(defaultValue = "10") Integer pageSize) {
        List<OperateLog> rows = operateLogService.findAllLogs(operateLog, page, pageSize);
        Long total =  ((Page)rows) .getTotal();
        if (operateLog != null) return Result.success(new PageResult(total, rows));
        else return Result.error("查询失败");
    }
}
